import 'package:bot_toast/src/basis.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:freedom/const/app_content.dart';
import 'package:freedom/entity/meta/meta_user_channel.dart';
import 'package:freedom/widget/common_alter_dialog.dart';

typedef CallBack = void Function(String roomCode);

typedef BtnCallBack = void Function();

void _defaultOnTap() {}

class Confirm extends StatefulWidget {
  final CallBack? callback;
  final MetaUserChannel? userChannel;
  final BtnCallBack? confirm;
  final BtnCallBack? cancel;
  final String? tips;
  CancelFunc? closeWindow;
  Confirm(
      {super.key,
      this.callback,
      this.userChannel,
      this.confirm = _defaultOnTap,
      this.cancel = _defaultOnTap,
      this.tips = "",
      this.closeWindow});
  @override
  ConfirmState createState() => ConfirmState();
}

class ConfirmState extends State<Confirm> {
  double dialogHeight = 120.h, dialogWidth = 300.h;
  BtnCallBack? _confirm;
  BtnCallBack? _cancel;
  CancelFunc? get closeWindow => widget.closeWindow;

  @override
  void initState() {
    super.initState();
    _confirm = widget.confirm;
    _cancel = widget.cancel;
  }

  @override
  Widget build(BuildContext context) {
    return CommonAlterDialog(
        height: dialogHeight,
        width: dialogWidth,
        closeWindow: closeWindow,
        child: Container(
          padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 30.h),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10.h),
            color: Colors.white,
            /* border: Border.all(color: Colors.orange.withOpacity(0.2)) */
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Text(
                widget.tips!,
                style: TextStyle(fontSize: 18.sp),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  buildButtion(text: "确定", onTap: _confirm!),
                  buildButtion(
                      background: Colors.orange, text: "取消", onTap: _cancel!),
                ],
              )
            ],
          ),
        ));
  }

  Widget buildButtion(
      {double? width,
      double? height,
      Color background = Colors.green,
      String text = "",
      BtnCallBack onTap = _defaultOnTap}) {
    return SizedBox(
      height: 30.h,
      width: 70.h,
      child: MaterialButton(
        color: background,
        shape: RoundedRectangleBorder(
          //边框颜色
          side: const BorderSide(
            color: Colors.white,
            width: 1,
          ),
          //边框圆角
          borderRadius: BorderRadius.all(
            Radius.circular(8.r),
          ),
        ),
        /*  style: ButtonStyle(
          backgroundColor: MaterialStateProperty.resolveWith((states) {
            //设置按下时的背景颜色
            if (states.contains(MaterialState.pressed)) {
              return Colors.blue[200];
            }
            //默认不使用背景颜色
            return background;
          }),
          elevation: MaterialStateProperty.all(12),
          shape: MaterialStateProperty.all(const StadiumBorder()),
        ), */
        onPressed: onTap,
        child: Text(
          text,
          style: TextStyle(
              fontSize: 15.h,
              height: 1.0,
              fontFamily: AppContent.fontHyqmd,
              color: Colors.white),
        ),
      ),
    );
  }
}
